<?php
/**
 * Created by PhpStorm.
 * User: 彭奇
 * Date: 2018/9/28
 * Time: 10:00
 */
class mySql{
    private $mysql;
    private $db="test";
    private $host="127.0.0.1";
    private $user="root";
    private $pass="";
    private $charts="utf8";
    function __construct()
    {
        try{
            $this->mysql=new PDO("mysql:dbname={$this->db};host=$this->host","$this->user","$this->pass");
            $this->mysql->exec("SET NAMES '$this->charts';");
        }catch (Exception $e)
        {
            echo "连接失败";
            var_dump($e);
        }
    }
    function insert($sql){
        return $this->mysql->exec($sql);
    }
    function delete($sql){
        return $this->mysql->exec($sql);
    }
    function update($sql){
        return $this->mysql->exec($sql);
    }
    function select($sql){
        $res=$this->mysql->query($sql,PDO::FETCH_ASSOC);
        $arr=[];
        foreach ($res as$row)
        {
           $arr[]=$row;
        }
        return $arr;
    }
}